﻿using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using App.Common;
using QxFramework.Core;
using System;
public class SceneMonoBase : MonoBehaviour
{
    public SceneMonoData _sceneMono;

    [HideInInspector]
    public bool NotStartOnScene = false;
    [HideInInspector]
    public SceneMonoData sceneMonoData
    {
        get
        {
            return GameMgr.Get<ISceneMonoManager>().GetSceneMono(gameObject.name);
        }
    }
    public virtual void OnEnable()
    {
        transform.SetParent(GameObject.Find("SceneObjs").transform);
        
    }
    IEnumerator Init()
    {
        yield return 0;
        if (!NotStartOnScene) StartCoroutine(Init());
    }
    public virtual void Awake()
    {
    }
    public virtual void Update()
    {
    }
    public virtual void LateUpdate()
    {
    }
    public void Init(Vector3 StartPos,MonoAttribute MonoAttr)
    {
        if (!GameMgr.Get<ISceneMonoManager>().GetAllSceneMono()._sceneMonoDatas.ContainsKey(gameObject.name))
        {
            _sceneMono = new SceneMonoData();
            var ground = GameMgr.Get<IMapManager>().GetCertainGround((int)(transform.position.y * 2),(int)(transform.position.x * 2));
            if(ground != null)
            {
                _sceneMono.sceneType = ground.sceneType;
                _sceneMono.Params = ground.param;

            }
            _sceneMono.position = StartPos;
            _sceneMono.attr = MonoAttr;
            int i = 0;
            while (GameMgr.Get<ISceneMonoManager>().GetAllSceneMono()._sceneMonoDatas.ContainsKey(gameObject.name))
            {
                gameObject.name += "_" + i;
                i++;
            }
            GameMgr.Get<ISceneMonoManager>().AddSceneMono(gameObject.name, _sceneMono);
            GameMgr.Get<ISceneMonoManager>().AddSceneObj(gameObject.name, out GameObject gmobj);
        }
    }
    public virtual void OnDrawGizmos()
    {
    }
}
